<template>
	<view v-if="pageShow">
		<u-navbar title="个人主页" :titleStyle="{color:'#fff'}" bgColor="#3478F5" placeholder>
			<view class="u-nav-slot" slot="left">
				<u-icon name="arrow-left" size="19" color="#fff" @click="back"></u-icon>
			</view>
		</u-navbar>
		<view class="headbgc flexleft">
			<image :src="dataAll.avatar"
				class="headimg margin_right" mode=""></image>
			<view class="flexcolumnbet" style="width: 100%;">
				<view class="flexbetween" style="width: 100%;">
					<view class="titletext bai_text bold">{{dataAll.username}}</view>
					<view class="guanzhu xiaolan" @click="collect">{{dataAll.is_collect?"取消收藏":"收藏"}}</view>
				</view>
				<view class="xiaobai">{{dataAll.description}}</view>
			</view>
		</view>
		<view class="mainpadding contentmsg">
			<u-tabs lineColor="#3478F5" lineWidth="15" :scrollable="false" :activeStyle="{
			             color: '#000000',
			             fontWeight: 'bold',
			             transform: 'scale(1.05)'
			         }" :inactiveStyle="{
			             color: '#666666',
			             transform: 'scale(1)'
			         }" :list="list1" @change="tabChage"></u-tabs>
			<!-- 优课 -->
			<view class="flexcolumn" v-if="!list.data.length">
				<view class="placeholderimage"></view>
				<view class="margin_top xiaohui">暂无数据！</view>
			</view>
			<template v-if="tabsId==1">
				<view class="flexbetween flex_wrap">
					<view class="itemgoods ffffff radius margin_top" v-for="item in list.data" :key="item.id" @click="jumpurl('/pages_index/youkexq?id=',item.id)">
						<image :src="item.image_text" class="goodstopimg" mode=""></image>
						<view class="" style="padding: 30rpx 15rpx;">
							<view class="main_size hei_text bold xiankuan">{{item.name}}</view>
							<view class="flexbetween margin_top2">
								<view class="viplable" v-show="item.is_vip">vip</view>
								<view class="bianhao">编号：{{item.id}}</view>
							</view>
							<view class="flexbetween margin_top2">
								<view class="flexleft">
									<image :src="item.teacher.avatar" mode="" class="listheadimg"></image>
									<view class="xiaohei xiankuan margin_left1" style="width: 80rpx;">{{item.teacher.username}}</view>
								</view>
								<view class="xiaohong">￥{{item.price}}</view>
							</view>
						</view>
					</view>
				</view>
			</template>
			<!-- 辅导 -->
			<template v-if="tabsId==2">
				<view class="mainpadding_top ffffff radius" v-for="item in list.data" :key="item.id" @click="jumpurl('/pages_index/fudaoxq?id=',item.id)">
					<view class="yihang hei_text bold main_size">{{item.name}}</view>
					<view class="flexleft margin_top2">
						<view class="viplable margin_right" v-show="item.is_vip">vip</view>
						<view class="bianhao">编号：{{item.id}}</view>
					</view>
					<view class="flexbetween margin_top2">
						<view class="flexleft">
							<image :src="item.teacher.avatar" mode="" class="listheadimg"></image>
							<view class="xiaohei margin_left1">{{item.teacher.username}}</view>
						</view>
						<view class="xiaohong">￥{{item.price}}</view>
					</view>
				</view>
			</template>
			<!-- 测试 -->
			<template v-if="tabsId==3">
				<view class="mainpadding_top ffffff radius" v-for="item in list.data" :key="item.id"  @click="jumpurl('/pages_index/ceshixq?id=',item.id)">
					<view class="yihang hei_text bold main_size">{{item.name}}</view>
					<view class="flexbetween margin_top2">
						<view class="flexleft ">
							<view class="viplable margin_right" v-show="item.is_vip">vip</view>
							<view class="bianhao">编号：{{item.id}}</view>
						</view>
						<view class="xiaohong">￥{{item.price}}</view>
					</view>
					<view class="flexbetween margin_top2">
						<view class="flexleft">
							<image :src="item.teacher.avatar" mode="" class="listheadimg"></image>
							<view class="xiaohei margin_left1">{{item.teacher.username}}</view>
						</view>
						<view class="listbtnlan" v-if="!item.is_free" @click.stop="kecheng_pay(item.id)">立即购买</view>
						<view class="listbtnlan" v-if="item.is_free" @click.stop="jumpurl('/pages_mine/ceshitjq?id=',item.id)">立即考试</view>
					</view>
				</view>
			</template>
			<!-- 资料 -->
			<template v-if="tabsId==4">
				<view class="mainpadding_top ffffff radius" v-for="item in list.data" :key="item.id" @click="jumpurl('/pages_index/ziliaoxq?id=',item.id)">
					<view class="yihang hei_text bold main_size">{{item.name}}</view>
					<view class="flexleft margin_top2">
						<view class="viplable margin_right" v-show="item.is_vip">vip</view>
						<view class="bianhao">编号：{{item.id}}</view>
					</view>
					<view class="flexbetween margin_top2">
						<view class="flexleft">
							<image :src="item.teacher.avatar" mode="" class="listheadimg"></image>
							<view class="xiaohei margin_left1">{{item.teacher.username}}</view>
						</view>
						<view class="xiaohong">￥{{item.price}}</view>
					</view>
				</view>
			</template>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				list1: [{
					id: 1,
					name: '优课',
				}, {
					id: 2,
					name: '辅导',
				}, {
					id: 3,
					name: '测试',
				}, {
					id: 4,
					name: '资料',
				}],
				tabsId: 1, //默认优课
				pageShow:false,
				dataAll:{},
				page: 1,
				limit: 12,
				list: {
					data: []
				},
			}
		},
		onLoad(options) {
			this.listid = options.id
			this.getDetail()
			this.init()
		},
		methods: {
			kecheng_pay(id) {
				httpRequest.request('/api/lesson/create_order', 'POST', {
					education_lesson_id: id
				}, false, false, true).then(res => {
					if (res.code == 1) {
						let data = {
							pay_price: res.data.pay_price,
							order_id: res.data.order_id
						}
						uni.redirectTo({
							url: '/pages_index/kechengddzf?msg=' + encodeURIComponent(JSON
								.stringify(data))
						})
					} else {
						httpRequest.toast(res.msg);
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			init(isPage, page) {
				let _this = this;
				httpRequest.request('/api/lesson/getlist', 'GET', {
					page: page || 1,
					type:this.tabsId,
					teacher_id:this.listid
				}, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			getDetail(){
				httpRequest.request('/api/teacher/getdetail', 'GET', {
					id: this.listid
				}, false, false, true).then(res => {
					if (res.code == 1) {
						this.dataAll = res.data
						this.pageShow = true
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			collect(){//收藏
				httpRequest.request('/api/teacher/collects', 'POST', {
					id: this.listid
				}, false, false, true).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						this.dataAll.is_collect = this.dataAll.is_collect?false:true
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			tabChage(e) {
				this.tabsId = e.id
				this.init()
			},
			jumpurl(url,id){
				uni.navigateTo({
					url:url+id
				})
			},
			back(){
				uni.navigateBack(1)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.headbgc {
		background: linear-gradient(180deg, #3478F5 0%, #5499FF 100%);
		padding: 80rpx 30rpx;

	}

	.guanzhu {
		background-color: #fff;
		border-radius: 50rpx;
		padding: 10rpx 30rpx;
	}

	.contentmsg {
		border-radius: 30rpx 30rpx 0 0;
		position: relative;
		top: -30rpx;
		background-color: #fafafa;
	}
</style>